package edu.hawaii.myisern.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the Id class.
 * 
 * @author Randy Cox
 */
public class TestId {

  private String test = "Test Name";
  private String name = "  One TWO Three Four five  ";
  private String expected = "ONE_TWO_THREE_FOUR_FIVE";

  /**
   * Test buildId from a typical name field.
   */
  @Test
  public void testBuldId() {
    assertEquals("Id should replace spaces with underscore", expected, Id.build(name));
  }

  /**
   * Test creation of Id class.
   */
  @Test
  public void testIdConstructor() {
    Id id = new Id();
    assertTrue("Id should be empty", id.toString().isEmpty());

    id = new Id(name);
    assertEquals("Id.toString should be in ID form", expected, id.toString());
    assertEquals("Id.getID should be in ID form", expected, id.getId());

    Id id1 = new Id(test);
    Id id2 = new Id(test);
    assertEquals("Hashcodes should be the same", id1.hashCode(), id2.hashCode());

    id.setId(test);
    assertEquals("Test setId()", Id.build(test), id.getId());

    String empty = Id.build(null);
    assertTrue("Empty should be empty", empty.isEmpty());
  }

  /**
   * Test equals method.
   */
  @Test
  public void testEquals() {
    String name1 = name;
    String name2 = name;
    String name3 = name + " six  ";

    Id id1 = new Id(name1);
    Id id2 = new Id(name2);
    assertEquals("Ids are equal", id1, id2);

    Id id3 = new Id(name3);
    assertFalse("Ids are not equal", id1.equals(id3));
  }
}
